package com.study.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{HashPartitioner, SparkConf, SparkContext}

object Scala14_RDD_Operator_Transform{
  def main(args: Array[String]): Unit = {

    val conf = new SparkConf().setMaster("local[*]").setAppName("RDD")
    conf.set("spark.local.dir","D:\\hadoopbook\\spark\\test")
    val sc = new SparkContext(conf)
    // TODO 算子 - 转换 -  K-V类型:reduceByKay
    val rdd: RDD[(String, Int)] = sc.makeRDD(
      List(
        ("a", 2),
        ("a", 3),
        ("a", 4)
      )
    )
    // reduceByKey算子的作用：将相同的key放到同一个组，对v进行统计处理
    // 可以实现WordCount 2
    val rdd1 = rdd.reduceByKey(_ + _)
    rdd1.collect().foreach(println)//(a,9)
    sc.stop()
  }
}
